/*
* 新增入库单材料明细
* */
import 'dart:convert';
import 'package:center_beijing/api/material_science_api.dart';
import 'package:center_beijing/api/product_api.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/notification.dart';
import 'package:center_beijing/common/numLengthInputFormatter.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/config/routeConfig.dart';
import 'package:center_beijing/models/selectItem.dart';
import 'package:center_beijing/widgets/custom_input_widget.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/custom_select_widget.dart';
import 'package:center_beijing/widgets/imageSelect_widget.dart';
import 'package:center_beijing/widgets/textarea_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart' as Go;
import 'package:dio/dio.dart' as ImageForm;
import 'package:images_picker/images_picker.dart';
import 'dart:io';
import 'package:http_parser/http_parser.dart';
class AddMaterialDetailWarehousing extends StatefulWidget {
  @override
  _AddMaterialDetailWarehousingState createState() =>
      _AddMaterialDetailWarehousingState();
}

class _AddMaterialDetailWarehousingState
    extends State<AddMaterialDetailWarehousing>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('提交中...');
  var receive = Go.Get.arguments;
  List<SelectItems> receiptType = [
    SelectItems(label: '是', value: '1'),
    SelectItems(label: '否', value: '0')
  ];
  SelectItems receipt = SelectItems();
  var specification = Map(); //规格型号
  final TextEditingController oddNumbers = TextEditingController(); //单号
  final TextEditingController measure = TextEditingController(); //计量单位
  final TextEditingController number = TextEditingController(); //数量
  final TextEditingController contract = TextEditingController(); //合同
  final TextEditingController unitPriceWithTax =
      TextEditingController(); //单价(含税)
  final TextEditingController unitPrice = TextEditingController(); //单价(不含税)
  final TextEditingController priceWithTax = TextEditingController(); //金额(含税)
  final TextEditingController price = TextEditingController(); //金额(不含税)
  final TextEditingController inPrice = TextEditingController(); //入账金额
  final TextEditingController source = TextEditingController(); //市场来源

  var totalPriceUnitPrice = '0';//采购金额不含税
  var totalPricePrice = '0';//采购金额含税
  String remark = '';
  List<Media> photos = [];
  ImageForm.FormData formData;
  List passPhoto = [];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    LogUtil.d(receive);
    this.setState(() {
      oddNumbers.text = receive['docNumber'];
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  justifyInfo() {
    if (specification['id'] == null) {
      Fluttertoast.showToast(msg: '请选择规格型号');
      return false;
    } else if (number.text == '') {
      Fluttertoast.showToast(msg: '请输入数量');
      return false;
    } else if (number.text == '0') {
      Fluttertoast.showToast(msg: '数量不能为0');
      return false;
    } else if (unitPriceWithTax.text == '' || unitPrice.text == '') {
      Fluttertoast.showToast(msg: '请输入采购单价');
      return false;
    } else if (inPrice.text == '') {
      Fluttertoast.showToast(msg: '请输入入账金额');
      return false;
    } else if (receipt.value == null) {
      Fluttertoast.showToast(msg: '请选择是否预收');
      return false;
    }
    return true;
  }

  submit(type) async {
    var pass = {
      'item': json.encode({
        'projectSectionId': GlobalConfig.selectFactory.tag,
        'receiptType': receipt.value,
        'receiptGenid': receive['id'],
        'materialSpecId': specification['id'],
        'quantity': number.text,
        'unitPrice': unitPriceWithTax.text,
        'unitPriceExcludeTax': unitPrice.text,
        'recordedAmount': inPrice.text,
        'beforehandCash': receipt.value,
        'marketSource': source.text,
        'contractNumber': contract.text,
        'remark': remark,
        'attachmentList': passPhoto.map((e) =>  {
        "atchId": e['attachmentId'],
        "fileName": e['fileName'],
        "fileType":e['fileType'],
        }).toList()
      })
    };
    var result = await addReceivedEntry(pass);
    loading.dismiss();
    if (result != null && result['hasError'] == null) {
      Fluttertoast.showToast(msg: '提交成功');
      bus.emit('refreshReceiveDetailList');
      if (type == 1) {
        Go.Get.back();
      } else {
        Go.Get.offAndToNamed(RouteConfig.addMaterialDetailWarehousing,
            arguments: receive);
      }
    }
  }

  Future addImage(type) async {
    this.passPhoto = [];

    loading.show(delay: 30);
    if (this.photos.length > 0) {
      var temPhotos = [];
      temPhotos.addAll(this.photos);
      formData = new ImageForm.FormData.fromMap({
        "tenantId": GlobalConfig.tenantId,
      });
      for (int i = 0; i < temPhotos.length; i++) {
        Media asset = temPhotos[i];
        File file = File(asset.path);
        formData.files.add(MapEntry("files",
            await ImageForm.MultipartFile.fromFile(file.path.toString(),contentType: MediaType('image',file.path.toString().split('.').last))));
      }
      var result = await uploadImage(formData, GlobalConfig.tenantId);
      if (result != null && result.length > 0) {
        result.forEach((element){
          element['atchId'] = element['attachmentId'];
          element['fileName'] = element['fileName'].toString().substring(element['fileName'].length-8);
          element['fileType'] = 'png';
        });
        this.passPhoto = result;
        this.submit(type);
      }
    } else {
      this.submit(type);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('新增材料明细'),
        ),
        body: GestureDetector(
          onTap: (){
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Container(
            color: Styles.MainBackgroundColor,
            padding: EdgeInsets.fromLTRB(
                0, 0, 0, MediaQuery.of(context).padding.bottom + 70),
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '所属单号',
                      style: TextStyle(
                          color: Styles.DetailColor, fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      inputformat: [
                        LengthLimitingTextInputFormatter(20),
                      ],
                      borderWidth: 1,
                      backColor: Styles.GrayLight,
                      title: '',
                      placeHold: '请输入',
                      textInput: this.oddNumbers,
                      clearAll: false,
                      require: false,
                      readOnly: true,
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: "规格型号",
                            style: TextStyle(
                                fontSize: Styles.NormalFont,
                                color: Styles.DetailColor),
                          ),
                          TextSpan(
                            text: '*',
                            style: TextStyle(
                                fontSize: Styles.NormalFont, color: Styles.RedColor),
                          )
                        ])),
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.translucent,
                    onTap: () async {
                      var result =
                      await Go.Get.toNamed(RouteConfig.selectSpecifications);
                      if (result != null) {
                        this.setState(() {
                          specification = result;
                          this.measure.text =
                          specification['attr']['measureUnit'];
                        });
                      }
                    },
                    child: Container(
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border: Border.all(color: Styles.BlueColor, width: 1)),
                      padding: EdgeInsets.fromLTRB(Styles.spacing8,
                          Styles.spacing12, Styles.spacing8, Styles.spacing12),
                      margin: EdgeInsets.fromLTRB(
                          Styles.spacing16, 0, Styles.spacing16, 0),
                      child: Text(
                        this.specification['name'] != null
                            ? this.specification['name']
                            : '选择规格型号',
                        style: TextStyle(
                            color: Styles.BlueColor, fontSize: Styles.NormalFont),
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '计量单位',
                      style: TextStyle(
                          color: Styles.DetailColor, fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                      ],
                      borderWidth: 1,
                      backColor: Styles.GrayLight,
                      title: '',
                      placeHold: '选择规格型号后自动获取',
                      textInput: this.measure,
                      clearAll: false,
                      require: false,
                      readOnly: true,
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: "数量",
                            style: TextStyle(
                                fontSize: Styles.NormalFont,
                                color: Styles.DetailColor),
                          ),
                          TextSpan(
                            text: '*',
                            style: TextStyle(
                                fontSize: Styles.NormalFont, color: Styles.RedColor),
                          )
                        ])),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      borderWidth: 1,
                      keyboardType:TextInputType.numberWithOptions(decimal: true),
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                        NumLengthInputFormatter(digit: 2),
                      ],
                      title: '',
                      placeHold: '请输入',
                      textInput: this.number,
                      clearAll: false,
                      require: false,
                      focusChange: (){
                        this.setState(() {
                          totalPriceUnitPrice = (double.parse(this.unitPrice.text==''?'0':this.unitPrice.text)*int.parse(this.number.text==''?'0':this.number.text)).toString();
                          totalPricePrice = (double.parse(this.unitPriceWithTax.text==''?'0':this.unitPriceWithTax.text)*int.parse(this.number.text==''?'0':this.number.text)).toString();
                        });
                      },
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '供货合同',
                      style: TextStyle(
                          color: Styles.DetailColor, fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      borderWidth: 1,
                      inputformat: [
                        LengthLimitingTextInputFormatter(15),
                      ],
                      title: '',
                      placeHold: '请输入',
                      textInput: this.contract,
                      clearAll: false,
                      require: false,
                    ),
                  ),
                  Row(
                    children: [
                      Expanded(
                          child: Container(
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.centerLeft,
                                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                                  child: RichText(
                                      text: TextSpan(children: [
                                        TextSpan(
                                          text: "采购单价(含税)/元",
                                          style: TextStyle(
                                              fontSize: Styles.NormalFont,
                                              color: Styles.DetailColor),
                                        ),
                                        TextSpan(
                                          text: '*',
                                          style: TextStyle(
                                              fontSize: Styles.NormalFont, color: Styles.RedColor),
                                        )
                                      ])),
                                ),

                                Container(
                                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                  padding: EdgeInsets.fromLTRB(
                                      Styles.spacing8, 0, Styles.spacing8, 0),
                                  child: CustomInput(
                                    textAlign: TextAlign.left,
                                    keyboardType: TextInputType.numberWithOptions(
                                        decimal: true),
                                    borderWidth: 1,
                                    inputformat: [
                                      LengthLimitingTextInputFormatter(10),
                                      NumLengthInputFormatter(digit: 2)
                                    ],
                                    title: '',
                                    placeHold: '请输入',
                                    textInput: this.unitPriceWithTax,
                                    clearAll: false,
                                    require: false,
                                    focusChange: (){
this.setState(() {
  totalPricePrice = (double.parse(this.unitPriceWithTax.text==''?'0':this.unitPriceWithTax.text)*int.parse(this.number.text==''?'0':this.number.text)).toString();
});
                                    },
                                  ),
                                ),
                              ],
                            ),
                          )),
                      Expanded(
                          child: Container(
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.centerLeft,
                                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                                  child: RichText(
                                      text: TextSpan(children: [
                                        TextSpan(
                                          text: "采购单价(不含税)/元",
                                          style: TextStyle(
                                              fontSize: Styles.NormalFont,
                                              color: Styles.DetailColor),
                                        ),
                                        TextSpan(
                                          text: '*',
                                          style: TextStyle(
                                              fontSize: Styles.NormalFont, color: Styles.RedColor),
                                        )
                                      ])),
                                ),
                                Container(
                                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                  padding: EdgeInsets.fromLTRB(
                                      Styles.spacing8, 0, Styles.spacing8, 0),
                                  child: CustomInput(
                                    textAlign: TextAlign.left,
                                    keyboardType: TextInputType.numberWithOptions(
                                        decimal: true),
                                    borderWidth: 1,
                                    inputformat: [
                                      LengthLimitingTextInputFormatter(10),
                                      NumLengthInputFormatter(digit: 2)
                                    ],
                                    title: '',
                                    placeHold: '请输入',
                                    textInput: this.unitPrice,
                                    clearAll: false,
                                    require: false,
                                    focusChange: (){

this.setState(() {
  totalPriceUnitPrice = (double.parse(this.unitPrice.text==''?'0':this.unitPrice.text)*int.parse(this.number.text==''?'0':this.number.text)).toString();
});
                                    },
                                  ),
                                ),
                              ],
                            ),
                          ))
                    ],
                  ),
                  Row(
                    children: [
                      Expanded(
                          child: Container(
                        child: Column(
                          children: [
                            Container(
                              alignment: Alignment.centerLeft,
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing16,
                                  Styles.spacing12,
                                  Styles.spacing8,
                                  Styles.spacing8),
                              child: Text(
                                '采购金额(含税)/元',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.NormalFont),
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8, 0, Styles.spacing8, 0),
                              child: Text(double.parse(totalPricePrice).toStringAsFixed(2),style: TextStyle(color: Styles.DetailColor,fontSize: Styles.NormalFont),),
                            ),
                          ],
                        ),
                      )),
                      Expanded(
                          child: Container(
                        child: Column(
                          children: [
                            Container(
                              alignment: Alignment.centerLeft,
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing16,
                                  Styles.spacing12,
                                  Styles.spacing8,
                                  Styles.spacing8),
                              child: Text(
                                '采购金额(不含税)/元',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.NormalFont),
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8, 0, Styles.spacing8, 0),
                              child: Text(double.parse(totalPriceUnitPrice).toStringAsFixed(2),style: TextStyle(color: Styles.DetailColor,fontSize: Styles.NormalFont),),
                            ),
                          ],
                        ),
                      ))
                    ],
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: "入账金额",
                            style: TextStyle(
                                fontSize: Styles.NormalFont,
                                color: Styles.DetailColor),
                          ),
                          TextSpan(
                            text: '*',
                            style: TextStyle(
                                fontSize: Styles.NormalFont, color: Styles.RedColor),
                          )
                        ])),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      keyboardType:
                      TextInputType.numberWithOptions(decimal: true),
                      borderWidth: 1,

                      inputformat: [
                        LengthLimitingTextInputFormatter(20),
                        NumLengthInputFormatter(digit: 2)
                      ],
                      title: '',
                      placeHold: '请输入',
                      textInput: this.inPrice,
                      clearAll: false,
                      require: false,
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: "是否预收",
                            style: TextStyle(
                                fontSize: Styles.NormalFont,
                                color: Styles.DetailColor),
                          ),
                          TextSpan(
                            text: '*',
                            style: TextStyle(
                                fontSize: Styles.NormalFont, color: Styles.RedColor),
                          )
                        ])),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomSelectWidget(
                      require: false,
                      rightText: receipt.label != null ? receipt.label : '请选择',
                      titleFont: Styles.NormalFont,
                      items: receiptType,
                      selectCallback: (value) => this.setState(() {
                        receipt = value;
                      }),
                      title: '是否预收',
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '市场来源',
                      style: TextStyle(
                          color: Styles.DetailColor, fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      borderWidth: 1,
                      inputformat: [],
                      title: '',
                      placeHold: '请输入',
                      textInput: this.source,
                      clearAll: false,
                      require: false,
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(
                        Styles.spacing8, Styles.spacing8, Styles.spacing8, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: TextAreaWidget(
                      labelText: '备注',
                      defaultValue: '',
                      placeholder: '请输入备注',
                      disabled: false,
                      required: false,
                      rows: 4,
                      onChange: (value) => this.setState(() {
                        remark = value;
                      }),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    color: Colors.white,
                    child: Column(
                      children: [
                        Padding(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16, Styles.spacing8, 0, 0),
                          child: Row(
                            children: <Widget>[
                              Text(
                                '照片(${this.photos.length}/6)',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.MiddleFont17),
                              ),
                            ],
                          ),
                        ),
                        ImageSelectWidget(
                          onchange: (value) {
                            this.setState(() {
                              photos = value;
                            });
                          },
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Container(
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
              Styles.spacing8, Styles.spacing8, Styles.spacing8, 10),
          child: Row(
            children: [
              Expanded(
                  flex: 1,
                  child: Container(
                    decoration: new BoxDecoration(
                      border: Border.all(width: 1, color: Styles.BlueColor),
                      //背景
                      color: Styles.LightBlueColor,
                      //设置四周圆角 角度
                      borderRadius: BorderRadius.all(Radius.circular(12.0)),
                    ),
                    margin: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: FlatButton(
                        onPressed: () {
                          FocusScope.of(context).requestFocus(new FocusNode());
                          if (justifyInfo()) {
                            showDialog(
                                barrierDismissible: false,
                                context: this.context,
                                builder: (BuildContext context) {
                                  return AlertDialog(
                                    title: Text('注意'),
                                    content: Text('确认完成吗？'),
                                    actions: <Widget>[
                                      new Container(
                                        child: FlatButton(
                                          child: new Text(
                                            "取消",
                                            style:
                                                TextStyle(color: Colors.black),
                                          ),
                                          onPressed: () {
                                            Navigator.pop(context);
                                          },
                                        ),
                                      ),
                                      new Container(
                                        child: FlatButton(
                                          child: new Text(
                                            "确定",
                                            style: TextStyle(color: Colors.red),
                                          ),
                                          onPressed: () {
                                            Navigator.pop(context);
                                            this.addImage(1);
                                          },
                                        ),
                                      ),
                                    ],
                                  );
                                });
                          }
                        },
                        child: Container(
                          height: Styles.MainButtonHeight,
                          alignment: Alignment.center,
                          child: Text('完成',
                              style: TextStyle(
                                  color: Styles.BlueColor,
                                  fontSize: Styles.MainButtonTextFont)),
                        )),
                  )),
              Expanded(
                  flex: 1,
                  child: Container(
                    decoration: new BoxDecoration(
                      //背景
                      color: Styles.BlueColor,
                      //设置四周圆角 角度
                      borderRadius: BorderRadius.all(Radius.circular(12.0)),
                    ),
                    margin: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: FlatButton(
                        onPressed: () {
                          FocusScope.of(context).requestFocus(new FocusNode());
                          if(justifyInfo()){
                            showDialog(
                                barrierDismissible: false,
                                context: this.context,
                                builder: (BuildContext context) {
                                  return AlertDialog(
                                    title: Text('注意'),
                                    content: Text('确认完成吗？'),
                                    actions: <Widget>[
                                      new Container(
                                        child: FlatButton(
                                          child: new Text(
                                            "取消",
                                            style: TextStyle(color: Colors.black),
                                          ),
                                          onPressed: () {
                                            Navigator.pop(context);
                                          },
                                        ),
                                      ),
                                      new Container(
                                        child: FlatButton(
                                          child: new Text(
                                            "确定",
                                            style: TextStyle(color: Colors.red),
                                          ),
                                          onPressed: () {
                                            Navigator.pop(context);
                                            this.addImage(2);
                                          },
                                        ),
                                      ),
                                    ],
                                  );
                                });
                          }
                        },
                        child: Container(
                          height: Styles.MainButtonHeight,
                          alignment: Alignment.center,
                          child: Text('完成并继续添加',
                              style: TextStyle(
                                  color: Styles.WhiteGray,
                                  fontSize: Styles.MainButtonTextFont)),
                        )),
                  ))
            ],
          ),
        ));
  }
}
